package com.study.mike;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.EasyExcel;
import com.study.mike.model.dto.Users;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author KangHui
 * @Date 2023/7/20 14:15
 */
public class Test {
    public static void main(String[] args) {
        String excelFilePath = "C:\\Users\\James\\Desktop\\" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN) + ".xlsx";
        try (Workbook workbook = new XSSFWorkbook()) {

            Sheet sheet = workbook.createSheet("Sheet1");
            Row row = sheet.createRow(0);

            List<String> platforms = Arrays.asList("淘宝", "京东", "拼多多", "艾玛优品", "享乐购", "抹了多","爱购物","欧菲斯","爱甩货","极致购物");

            // 在工作表中写入数据
            // 固定头部内容（系统的平台）
            for (int i = 0; i < platforms.size(); i++) {
                Cell cell = row.createCell(i);
                cell.setCellValue(platforms.get(i));
                if (i==0) {
                    cell.setCellValue("项目名称");
                }
            }

            // 写入数据
            for (int i = 0; i < 5; i++) {
                Row row1 = sheet.createRow(i + 1);
                for (int j = 0; j < 10; j++) {
                    Cell cell1 = row1.createCell(j);
                    cell1.setCellValue(j);
                    if (j == 0) {
                        cell1.setCellValue("国网项目");
                    }
                }
            }


//            Row row1 = sheet.createRow(1);
//            Cell cell1 = row1.createCell(1);
//            cell1.setCellValue("项目名称");
//
//            Row row2 = sheet.createRow(2);
//            Cell cell2 = row2.createCell(1);
//            cell2.setCellValue("John Doe");
//
//            Row row3 = sheet.createRow(3);
//            Cell cell3 = row3.createCell(1);
//            cell3.setCellValue("Jane Smith");

//            Row row4 = sheet.createRow(1);
//            Cell cell4 = row4.createCell(1);
//            cell4.setCellValue("数值1");
//
//            Row row5 = sheet.createRow(1);
//            Cell cell5 = row5.createCell(1);
//            cell5.setCellValue("数值2");


            // 保存Excel文件
            try (OutputStream outputStream = new FileOutputStream(excelFilePath)) {
                workbook.write(outputStream);
            }

            System.out.println("Excel exported successfully!");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
